package com.itheima.tliasmanager.service.Impl;

import com.itheima.tliasmanager.mapper.EmpMapper;
import com.itheima.tliasmanager.mapper.StudentMapper;
import com.itheima.tliasmanager.pojo.Dto.ClazzCount;
import com.itheima.tliasmanager.pojo.Dto.GenderCount;
import com.itheima.tliasmanager.pojo.Dto.JobCount;
import com.itheima.tliasmanager.pojo.Vo.ClazzVo;
import com.itheima.tliasmanager.pojo.Vo.JobVo;
import com.itheima.tliasmanager.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;


    @Override
    public JobVo empJobReport() {
        log.info("员工职位报表");
        List<JobCount> jobCountList = empMapper.countByJob();

        List<String> jobList = jobCountList.stream().map(j -> j.getJob()).collect(Collectors.toList());
        List<Integer> dataList = jobCountList.stream().map(j -> j.getCount()).collect(Collectors.toList());

        /*for (int i = 0; i < jobList.size(); i++) {
            String jobName = jobList.get(i);
            switch (jobName) {
                case "1":
                    jobList.set(i, "班主任");
                    break;
                case "2":
                    jobList.set(i, "讲师");
                    break;
                case "3":
                    jobList.set(i, "学工主管");
                    break;
                case "4":
                    jobList.set(i, "教研主管");
                    break;
                default:
                    jobList.set(i, "咨询师");
            }
        }*/

        return new JobVo(jobList, dataList);
    }

    @Override
    public ClazzVo studentCountReport() {
        log.info("统计每一个班级的人数");
        List<ClazzCount> clazzCountList = studentMapper.countByClazz();
        List<String> clazzList = clazzCountList.stream().map(c -> c.getClazz()).collect(Collectors.toList());
        List<Integer> dataList = clazzCountList.stream().map(c -> c.getCount()).collect(Collectors.toList());
        return new ClazzVo(clazzList, dataList);
    }

    @Override
    public List<GenderCount> empGenderReport() {
        log.info("员工性别报表");
        List<GenderCount> genderCountList =empMapper.countByGender();
        return genderCountList;
    }

    @Override
    public List<GenderCount> studentDegreeReport() {
        log.info("统计学员的学历信息");
        List<GenderCount> degreeCountList = studentMapper.countByDegree();

        return degreeCountList;
    }
}
